<?php
namespace app\hotback\logic\welcome;

use app\common\basics\Logic;
use app\common\logic\TechnLevelLogic;
use think\Cache;
use think\Db;



/**
 * 工作台统计
 * Class StatLogic
 * @package app\admin\logic\index
 */
class WelcomeLogic extends Logic
{



    /**
     * 获取数据统计页面信息
     * admin 子后台或分后台
     * max_time 结束时间
     **/
    public static function getWelcome($min_time = null,$max_time = null){
        if (!empty($min_time)){
            $where['add_time'] = ['>=',$min_time];
        }
        if (!empty($max_time)){
            $where['add_time'] = ['<',$max_time];
        }
        if (!empty($max_time) && !empty($min_time)){
            $where['add_time'] = ['between', $min_time.','.$max_time];
        }
        $where['id'] = ['>',-1];
        $data['all_money'] = Db::name('pay_log')
            ->where('payment','in','Weixin,Alipay')
            ->where($where)
            ->sum('pay_price');

//        $data['techn_money'] = Db::name('balance')
//            ->where('balance_type',1)
//            ->where('identity_type','techn')
//            ->where('identity_id','<>',299)
//            ->where($where)
//            ->where('status',1)
//            ->sum('yes_money');

        $data['techn_money'] = Db::name('balance')
            ->alias('b')
            ->join('order o','o.id = b.order_id')
            ->join('pay_log p','o.id = p.order_id')
            ->where('b.msg','技师分成')
//            ->where('b.balance_type',1)
//            ->where('b.identity_type','techn')
            ->where($where)
            ->where('b.status',1)
            ->sum('b.yes_money');

//        $data['money_car'] = Db::name('balance')
//            ->where('balance_type',2)
//            ->where('identity_id','<>',299)
//            ->where($where)
//            ->where('status',1)
//            ->sum('yes_money');
        $data['money_car'] = Db::name('balance')
            ->alias('b')
            ->join('order o','o.id = b.order_id')
            ->join('pay_log p','o.id = p.order_id')
            ->where('b.balance_type',2)
            ->where($where)
            ->where('b.status',1)
            ->sum('b.yes_money');

        $data['money_user'] = Db::name('balance')
            ->alias('b')
            ->join('order o','o.id = b.order_id')
            ->join('pay_log p','o.id = p.order_id')
            ->where('b.balance_type',3)
            ->where($where)
            ->where('b.status',1)
            ->sum('b.yes_money');

        $data['money_user'] += Db::name('balance')
            ->alias('b')
            ->join('order o','o.id = b.order_id')
            ->join('pay_log p','o.id = p.order_id')
            ->where('b.balance_type',4)
            ->where($where)
            ->where('b.status',1)
            ->sum('b.yes_money');


        $data['proxy_money'] = Db::name('balance')
            ->where($where)
            ->where('balance_type',1)
            ->where('identity_type','proxy')
            ->where('status',1)
            ->sum('yes_money');

        $data['refund'] = Db::name('refund_log')->where($where)->sum('refund_price');

        $data['order_num'] = Db::name('order')->where($where)->where('techn_id','<>',299)->count('id');

        $data['order_finish'] = Db::name('order')->where('techn_id','<>',299)->where($where)->where('status',6)->count('id');

        $data['cleat_money'] = round($data['all_money'] - $data['techn_money'] - $data['money_car'] - $data['money_user'] - $data['techn_header'] - $data['proxy_money'] - $data['refund'],2);

        return $data;
    }

    public static function get_money_data($min_time = null,$max_time = null,$proxy_id = null){
        if (!empty($min_time)){
            $where['p.add_time'] = ['>=',$min_time];
            $owhere['o.add_time'] = ['>=',$min_time];
        }
        if (!empty($max_time)){
            $owhere['o.add_time'] = ['<',$max_time];
            $where['p.add_time'] = ['<',$max_time];
        }
        if (!empty($max_time) && !empty($min_time)){
            $where['p.add_time'] = ['between', $min_time.','.$max_time];
            $owhere['o.add_time'] = ['between', $min_time.','.$max_time];
        }

        $where['p.id'] = ['>',-1];
        $owhere['o.id'] = ['>',-1];

        $data['order_money'] = Db::name('order')
            ->alias('o')
            ->where($owhere)
            ->where('o.pay_status','<>',0)
            ->where('user_id','<>',299)
            ->field('o.id,o.pay_price,o.refund_price')
            ->sum('o.pay_price+o.preferential_price');

        $data['refund'] = Db::name('order')
            ->alias('o')
            ->where('o.status','<>',0)
            ->where('o.status','<>',1)
            ->where($owhere)
            ->where('user_id','<>',299)
            ->sum('o.refund_price');

        $data['all_money'] = Db::name('pay_log')
            ->alias('p')
            ->where('p.payment','in','Weixin,Alipay')
            ->where($where)
            ->sum('p.pay_price');

        $data['coupon'] = Db::name('order')
            ->alias('o')
            ->where($owhere)
            ->where('o.pay_status','<>',0)
            ->where('user_id','<>',299)
            ->sum('o.preferential_price');
        $data['have_money'] = $data['order_money'] - $data['refund'] - $data['coupon'];

        $order_ids = Db::name('order')
            ->alias('o')
            ->join('pay_log p','p.order_id = o.id')
            ->where($owhere)
            ->column('o.id');

        $data['techn_money'] = Db::name('balance')
//            ->where('identity_id','in',$techn_ids)
            ->where('order_id','in',$order_ids)
            ->where('status',1)
            ->where('balance_type',1)
            ->where('identity_type','techn')
            ->sum('yes_money');

        $data['money_car'] = Db::name('balance')
//            ->where('identity_id','in',$techn_ids)
            ->where('order_id','in',$order_ids)
            ->where('status',1)
            ->where('balance_type',2)
            ->where('identity_type','techn')
            ->sum('yes_money');


        $data['money_user'] = Db::name('balance')
            ->where('order_id','in',$order_ids)
            ->where('status',1)
            ->where('balance_type','in','3,4')
//            ->where('identity_type','techn')
            ->sum('yes_money');



//        $data['order_num'] = Db::name('order')
//            ->alias('o')
//            ->join('pay_log p','o.id = p.order_id')
//            ->where($where)
//            ->where('o.techn_id','<>',299)
//            ->count('o.id');
//
//        $data['order_finish'] = Db::name('order')
//            ->alias('o')
//            ->join('pay_log p','o.id = p.order_id')
//            ->where($where)
//            ->where('o.status',6)
//            ->where('o.techn_id','<>',299)
//            ->count('o.id');


        $data['cleat_money'] = round($data['order_money'] - $data['techn_money'] - $data['money_car'] - $data['money_user'] - $data['coupon']  - $data['refund'],2);
        $bei = Db::name('proxy')->where('user_name','太原')->find();
        $data['order_money'] = $bei['beishu']*$data['order_money'];
        $data['refund'] = $bei['beishu']*$data['refund'];
        $data['all_money'] = $bei['beishu']*$data['all_money'];
        $data['coupon'] = $bei['beishu']*$data['coupon'];
        $data['have_money'] = $bei['beishu']*$data['have_money'];
        $data['techn_money'] = $bei['beishu']*$data['techn_money'];
        $data['money_car'] = $bei['beishu']*$data['money_car'];
        $data['money_user'] = $bei['beishu']*$data['money_user'];
        $data['cleat_money'] = $bei['beishu']*$data['cleat_money'];

        foreach ($data as $key=>$value){
            $data[$key]  = round($value,2);
        }
        return $data;
    }


    public static function get_proxy_money_data($min_time = null,$max_time = null,$proxy_id = null){
        $bei = 1;
        if (!empty($min_time)){
            $owhere['o.add_time'] = ['>=',$min_time];
        }
        if (!empty($max_time)){
            $owhere['o.add_time'] = ['<',$max_time];
        }

        if (!empty($max_time) && !empty($min_time)){
            $proxy_add_time = Db::name('proxy')->where('proxy_id',$proxy_id)->find();
            if ($proxy_add_time['add_time'] > $min_time){
                $min_time = $proxy_add_time['add_time'];
            }
            $owhere['o.add_time'] = ['between', $min_time.','.$max_time];
        }
        if (!empty($proxy_id)){
            $in = Db::name('proxy')->where('proxy_id',$proxy_id)->find();
            if ($in['is_xian'] == 1){
                $owhere['o.qu'] = $in['qu'];
            }else{
                $not = Db::name('proxy')->where('shi',$in['shi'])->where('proxy_id','<>',$in['proxy_id'])->where('is_xian',1)->column('qu');
                $owhere['o.shi'] = $in['shi'];
                if (!empty($not)){
                    $owhere['o.qu'] = ['not in',$not];
                }
            }
            $bei = Db::name('proxy')->where('proxy_id',$proxy_id)->value('beishu');
        }
        $owhere['o.id'] = ['>',-1];

        $data['order_money'] = Db::name('order')
            ->alias('o')
            ->where($owhere)
            ->where('o.pay_status','<>',0)
            ->where('user_id','<>',299)
//            ->field('o.id,o.pay_price,o.refund_price')
            ->sum('o.pay_price+o.preferential_price');

        $data['refund'] = Db::name('order')
            ->alias('o')
            ->where('o.status','<>',0)
            ->where('o.status','<>',1)
            ->where($owhere)
            ->where('user_id','<>',299)
            ->sum('o.refund_price');


        $data['coupon'] = Db::name('order')
            ->alias('o')
            ->where('o.pay_status','<>',0)
            ->where($owhere)
            ->where('user_id','<>',299)
            ->sum('o.preferential_price');
        $data['have_money'] = $data['order_money'] - $data['refund'] - $data['coupon'];


        $order_ids = Db::name('order')
            ->alias('o')
            ->join('pay_log p','p.order_id = o.id')
            ->where($owhere)
            ->column('o.id');


        $data['techn_money'] = Db::name('balance')
//            ->where('identity_id','in',$techn_ids)
            ->where('order_id','in',$order_ids)
            ->where('status',1)
            ->where('balance_type',1)
            ->where('identity_type','techn')
            ->sum('yes_money');

        $data['money_car'] = Db::name('balance')
//            ->where('identity_id','in',$techn_ids)
            ->where('order_id','in',$order_ids)
            ->where('status',1)
            ->where('balance_type',2)
            ->where('identity_type','techn')
            ->sum('yes_money');


        $data['money_user'] = Db::name('balance')
            ->where('order_id','in',$order_ids)
            ->where('status',1)
            ->where('balance_type','in','3,4')
//            ->where('identity_type','techn')
            ->sum('yes_money');


        $data['chouyong'] = 0;
        if ($proxy_id != null){
            $proxy_bl = Db::name('proxy')->where('proxy_id',$proxy_id)->value('commission');
            if ($proxy_bl > 0){
                $data['chouyong'] = round((Db::name('balance')
                        ->where('order_id','in',$order_ids)
                        ->where('status',1)
                        ->where('balance_type',1)
                        ->where('identity_type','proxy')
                        ->sum('price'))*$proxy_bl/100,2);

            }
        }
        $data['cleat_money'] = round($data['order_money'] - $data['techn_money'] - $data['money_car'] - $data['chouyong'] - $data['money_user'] - $data['coupon']  - $data['refund'],2);

        $data['order_money'] = $bei*$data['order_money'];
        $data['refund'] = $bei*$data['refund'];
//        $data['all_money'] = $bei*$data['all_money'];
        $data['coupon'] = $bei*$data['coupon'];
        $data['have_money'] = $bei*$data['have_money'];
        $data['techn_money'] = $bei*$data['techn_money'];
        $data['money_car'] = $bei*$data['money_car'];
        $data['money_user'] = $bei*$data['money_user'];
        $data['chouyong'] = $bei*$data['chouyong'];
        $data['cleat_money'] = $bei*$data['cleat_money'];



        foreach ($data as $key=>$value){
            $data[$key]  = round($value,2);
        }
        return $data;
    }

    public static function get_people(){
        $data['user_num'] = Db::name('user')->count('id');
        $data['order_num'] = Db::name('order')->where('techn_id','<>',299)->count('id');
        $data['techn_num'] = Db::name('techn')->count('id');
        $data['techn_online'] = Db::name('techn')->where('work_status',1)->count('id');
        $bei = Db::name('proxy')->where('user_name','太原')->find();
        $data['user_num'] = $bei['beishu']*$data['user_num'];
        $data['order_num'] = $bei['beishu']*$data['order_num'];
        $data['techn_num'] = $bei['beishu']*$data['techn_num'];
        $data['techn_online'] = $bei['beishu']*$data['techn_online'];

        return $data;
    }
    public static function gettime($time){


    }


    /**
     * 获取订单价格
     * min_time 开始时间
     * max_time 结束时间
     **/
    public static function order_money(int $min_time = null,int $max_time = null,$proxy_id = null,$xian_id=null){
        if (!empty($min_time) && !empty($max_time)){
            $where['pay_time'] = [
                ['>=',$min_time],
                ['<',$max_time],
            ];
        }
        if (!empty($proxy_id)){
            $shi = Db::name('proxy')->where('proxy_id',$proxy_id)->value('shi');
            $where['shi'] = $shi;
        }
        if (!empty($xian_id)){
            $shi = Db::name('proxy')->where('proxy_id',$proxy_id)->value('qu');
            $where['qu'] = $shi;

        }
        $where['status'] = ['in',[1,2,3,4,5,6]];
        $where['techn_id'] = ['<>',299];
        $sum = Db::name('order')
            ->where($where)
            ->sum('pay_price');
        return $sum;
    }

    public static function wechat_pay_money(int $min_time = null,int $max_time = null){
        if (!empty($min_time) && !empty($max_time)){
            $where['add_time'] = [
                ['>=',$min_time],
                ['<',$max_time],
            ];
        }
        $where['payment'] = 'Weixin';
        $sum = Db::name('pay_log')
            ->where($where)
            ->sum('total_price');
        $refund = Db::name('refund_log')
            ->where($where)
            ->sum('refund_price');
        return $return = ['sum' => $sum,'refund'=>$refund,'have'=>$sum-$refund];
    }

    public static function get_data(){
        $data = [];
        $star_time = strtotime('2023-03-05 00:00:00');
        while($star_time < time()){
            $end_time = $star_time + 86399;
            $time = ($star_time+28800)*1000;
            $money = Db::name('order')
                ->where('status','in',[1,2,3,4,5,6])
                ->where('add_time','>=',$star_time)
                ->where('add_time','<',$end_time)
                ->sum('pay_price');
            $money = round($money,2);

            $tmoney = Db::name('refund_log')
                ->where('add_time','>=',$star_time)
                ->where('add_time','<',$end_time)
                ->sum('pay_price');
            $tmoney = round($tmoney,2);
            $data[] = [$time,$money-$tmoney];
            $star_time += 86400;
        }
        return $data;
    }

    public static function city_list()
    {
        $city_list = Db::name('proxy')->where('is_delete_time', 0)->select();
        $city_money = [];
        $order_list = [];
        $day = date('d');
        if ($day >= 16){
            $min_time = strtotime(date('Y-m',time()).'-16 00:00:00');
            $max_time = strtotime(date('Y-',time()).(date('m',time())+1).'-1 00:00:00');
        }else{
            $min_time = strtotime(date('Y-m',time()).'-1 00:00:00');
            $max_time = strtotime(date('Y-m',time()).'-16 00:00:00');;
        }




        foreach ($city_list as $key => $in) {
            $where = [];
            $where['o.add_time'] = ['between', $min_time.','.$max_time];
            $where['o.id'] = ['>',-1];
            if ($in['is_xian'] == 1){
                $where['o.qu'] = $in['qu'];
            }else{
                $not = Db::name('proxy')->where('shi',$in['shi'])->where('proxy_id','<>',$in['proxy_id'])->where('is_xian',1)->column('qu');
                $where['o.shi'] = $in['shi'];
                if (!empty($not)){
                    $where['o.qu'] = ['not in',$not];
                }
            }

            $order_money = Db::name('order')
                ->alias('o')
                ->where($where)
                ->where('o.pay_status','<>',0)
                ->where('user_id','<>',299)
//            ->field('o.id,o.pay_price,o.refund_price')
                ->sum('o.pay_price');

            $refund = Db::name('order')
                ->alias('o')
                ->where('o.status','<>',0)
                ->where('o.status','<>',1)
                ->where($where)
                ->where('user_id','<>',299)
                ->sum('o.refund_price');

            $order_list[$in['proxy_id']]['proxy_id'] = $in['proxy_id'];
            $order_list[$in['proxy_id']]['price'] = $order_money - $refund;
            $order_list[$in['proxy_id']]['class_name'] = 'order'.$in['proxy_id'];


        }



        $sort = array_column($order_list,'price');
        array_multisort($sort,SORT_DESC,$order_list);


        foreach ($order_list as $key => $value){
            $order_list[$key]['ph_name'] = 'No.'.($key+1).':'.Db::name('proxy')->where('proxy_id',$value['proxy_id'])->value('user_name');

        }
        return $order_list;
    }

    public static function getcitywelcome($min = null,$max = null,$proxy){

        if (!empty($min)){
            $swhere['p.add_time'] = ['>=',$min];
            $rwhere['r.add_time'] = ['>=',$min];
        }
        if (!empty($max)){
            $swhere['p.add_time'] = ['<',$max];
            $rwhere['r.add_time'] = ['<',$max];
        }
        if (!empty($max) && !empty($min)){
            $swhere['p.add_time'] = ['between', $min.','.$max];
            $rwhere['r.add_time'] = ['between', $min.','.$max];
        }
        if (!empty($proxy['shi'])){
            $swhere['o.shi'] = $proxy['shi'];
            $rwhere['o.shi'] = $proxy['shi'];
        }
        if (!empty($proxy['not'])){
            $swhere['o.qu'] = ['not in',$proxy['not']];
            $rwhere['o.qu'] = ['not in',$proxy['not']];
        }
        if (!empty($proxy['qu'])){
            $swhere['o.qu'] = $proxy['qu'];
            $rwhere['o.qu'] = $proxy['qu'];
        }
        $swhere['p.id'] = ['>',-1];
        $rwhere['r.id'] = ['>',-1];
        $data['all_money'] = Db::name('pay_log')
            ->alias('p')
            ->join('order o','o.id = p.order_id')
//            ->where('p.payment','in','Weixin,Alipay')
            ->where($swhere)
            ->sum('o.pay_price');
        $data['refund'] = Db::name('refund_log')
            ->alias('r')
            ->join('order o','o.id = r.order_id')
            ->where($rwhere)
            ->sum('r.refund_price');
        $data['coupon'] = Db::name('pay_log')
            ->alias('p')
            ->join('order o','o.id = p.order_id')
            ->where('p.payment','in','Weixin,Alipay')
            ->where($swhere)
            ->sum('o.preferential_price');
        $data['have_money'] = $data['all_money'] - $data['refund'] - $data['coupon'];

        $data['techn_money'] = Db::name('balance')
            ->alias('b')
            ->join('order o','o.id = b.order_id')
            ->join('pay_log p','o.id = p.order_id')
            ->where('b.balance_type',1)
            ->where('b.identity_type','techn')
            ->where('b.identity_id','<>',299)
            ->where($swhere)
            ->where('b.status',1)
            ->sum('b.yes_money');


        $data['money_car'] = Db::name('balance')
            ->alias('b')
            ->join('order o','o.id = b.order_id')
            ->join('pay_log p','o.id = p.order_id')
            ->where('b.balance_type',2)
            ->where($swhere)
            ->where('b.status',1)
            ->sum('b.yes_money');


        $data['money_user'] = Db::name('balance')
            ->alias('b')
            ->join('order o','o.id = b.order_id')
            ->join('pay_log p','o.id = p.order_id')
            ->where('b.balance_type',3)
            ->where($swhere)
            ->where('b.status',1)
            ->sum('b.yes_money');

        $data['money_user'] += Db::name('balance')
            ->alias('b')
            ->join('order o','o.id = b.order_id')
            ->join('pay_log p','o.id = p.order_id')
            ->where('b.balance_type',4)
            ->where($swhere)
            ->where('b.status',1)
            ->sum('b.yes_money');

        $data['proxy_money'] = Db::name('balance')
            ->alias('b')
            ->join('order o','o.id = b.order_id')
            ->join('pay_log p','o.id = p.order_id')
            ->where('b.balance_type',1)
            ->where('b.identity_type','proxy')
            ->where($swhere)
            ->where('b.status',1)
            ->sum('b.yes_money');



        $data['order_num'] = Db::name('order')
            ->alias('o')
            ->join('pay_log p','o.id = p.order_id')
            ->where($swhere)
            ->where('o.techn_id','<>',299)
            ->count('o.id');

        $data['order_finish'] = Db::name('order')
            ->alias('o')
            ->join('pay_log p','o.id = p.order_id')
            ->where($swhere)
            ->where('o.status',6)
            ->where('o.techn_id','<>',299)
            ->count('o.id');

        $data['cleat_money'] = round($data['all_money'] - $data['techn_money'] - $data['money_car'] - $data['money_user'] - $data['coupon']  - $data['refund'],2);

        return $data;
    }

    public static function time(){
        $m = date('Y-m', strtotime(date('Y-m', time()) . '-1 00:00:00') - 1);
        $mm = date('Y-m-d', strtotime(date('Y-m', time()) . '-1 00:00:00') - 1);
        $return['minm'] = strtotime($m . '-01 00:00:00');
        $return['maxm'] = strtotime($mm . ' 23:59:59');
        $return['ymax'] = strtotime(date('Y-m-d', time())) - 1;
        $return['ymin'] = strtotime(date('Y-m-d', time())) - 86400;
        $return['day'] = strtotime(date('Y-m-d'));
        return $return;
    }

    public static function techn_list($type=null,$zhou=null){
        $day = date('d');
        if ($zhou == 1){
            $where['id'] = ['>',-1];
            $jwhere['j.id'] = ['>',-1];
        }

        if ($zhou == null){
            if ($day >= 16){
                $min = strtotime(date('Y-m',time()).'-16 00:00:00');
                $max = time();
            }else{
                $min = strtotime(date('Y-m',time()).'-1 00:00:00');
                $max = time();
            }
            $where['add_time'] = ['between',$min.','.$max];
            $jwhere['j.pay_time'] = ['between',$min.','.$max];

        }

        if ($zhou == 2){
            $min = strtotime(date('Y-m',time()).'-1 00:00:00');
            $m = date('m',time());
            $max = strtotime(date('Y-',time()).($m+1).'-1 00:00:00');
            $where['add_time'] = ['between',$min.','.$max];
            $jwhere['j.pay_time'] = ['between',$min.','.$max];
        }

        if ($zhou == 3){
            $test_Monday = date('Y-m-d',strtotime("last Sunday+1days"));

            $min = strtotime($test_Monday);
            $max = time();
            $where['add_time'] = ['between',$min.','.$max];
            $jwhere['j.pay_time'] = ['between',$min.','.$max];
        }




        $list = Db::name('techn')->where('work_status','<>',3)->where('id','<>',299)->where('orders_num','>',1)->select();
        $price = [];

        foreach ($list as $value){
//            $price[$value['id']]['price'] = Db::name('order_jz')
//                ->where('techn_id',$value['id'])
//                ->where($where)
//                ->sum('price');
//            $price[$value['id']]['price'] += Db::name('order_upgrade')
//                ->where('techn_id',$value['id'])
//                ->where($where)
//                ->sum('price');

            $price[$value['id']]['all_money'] = Db::name('order')
                ->where('techn_id',$value['id'])
                ->where($where)
                ->where('status',6)
                ->sum('price');

            $ids = Db::name('order')
                ->where('techn_id',$value['id'])
                ->where($where)
                ->column('id');
            $jz_money = Db::name('order_jz')->where('order_id','in',$ids)->sum('price');
            $jz_money += Db::name('order_upgrade')->where('order_id','in',$ids)->where('zftype',1)->sum('price');
            $price[$value['id']]['price'] = $jz_money;


            $price[$value['id']]['order_num'] = Db::name('order_jz')
                ->alias('j')
                ->join('order_jzdetail d','j.id = d.jz_id')
                ->where('j.techn_id',$value['id'])
                ->where($jwhere)
                ->sum('d.buy_number');

            $price[$value['id']]['order_num'] += Db::name('order_upgrade')
                ->where('techn_id',$value['id'])
                ->where($where)
                ->count('id');

            $jzl = TechnLevelLogic::jz_v($value['id'],$min,$max);

            $price[$value['id']]['jzl'] = $jzl;


            $price[$value['id']]['online'] = (float)(Db::name('techn_last')->where('techn_id',$value['id'])->value('total_duration'));
            $price[$value['id']]['jifen'] = Db::name('techn_last')->where('techn_id',$value['id'])->value('total_integral');
            $price[$value['id']]['techn_id'] = $value['id'];
            $price[$value['id']]['name'] = $value['nickname'];
            $price[$value['id']]['city'] = $value['city'];
            $price[$value['id']]['county'] = $value['county'];
            if ($price[$value['id']] == 0){
                unset($price[$value['id']]);
            }
        }
        if ($type == null || $type == 1){
//            usort($price, 'cmp');
            $sort = array_column($price,'price');
            array_multisort($sort,SORT_DESC,$price);

        }

        if ($type == 2){
//            usort($price, 'jzl');
            $sort = array_column($price,'jzl');
            array_multisort($sort,SORT_DESC,$price);

        }
        if  ($type == 3){
//            usort($price, 'online');
            $sort = array_column($price,'online');
            array_multisort($sort,SORT_DESC,$price);


        }

        if  ($type == 4){
//            usort($price, 'allmoney');
            $sort = array_column($price,'all_money');
            array_multisort($sort,SORT_DESC,$price);

        }


        if  ($type == 5){
//            usort($price, 'allmoney');
            $sort = array_column($price,'jifen');
            array_multisort($sort,SORT_DESC,$price);

        }


        foreach ($price as $kkk => $vvv){
            $price[$kkk]['online'] .= 'h';
            $price[$kkk]['jzl'] .= '%';
        }


        $return = [];
        foreach ($price as $kkk => $vvv){
            $return[$kkk] = $vvv;
            if ($kkk>8){
                break;
            }
        }


        foreach ($return as $rk => $rv){
            $city = Db::name('proxy')->where('qu',$rv['county'])->value('company_name');
            if (empty($city)){
                $city = Db::name('proxy')->where('shi',$rv['city'])->value('company_name');
            }
            $return[$rk]['city'] = $city;
            $return[$rk]['paixu'] = $rk+1;
        }
        return $return;
    }



}